#include <types.h>
#include <osal/osal.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <api/libosd/osd_lib.h>
#include <hld/dis/vpo.h>

#include "osdobjs_def.h"

#include "osd_config.h"
#include "string.id"
#include "images.id"
#include "win_pause.h"


/*******************************************************************************
* Objects definition
*******************************************************************************/

extern BITMAP win_pause_bmp;

static BOOL  cur_pause_state=UNPAUSE_STATE;	


DEF_BITMAP(win_pause_bmp,NULL,NULL,C_ATTR_ACTIVE,0, \
    1,0,0,0,0, PAUSE_L,PAUSE_T,PAUSE_W,PAUSE_H, WSTL_TRANS_IX,WSTL_TRANS_IX,0,0,   \
    NULL,NULL,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 0,0,PAUSE_ICON)

/*******************************************************************************
* Function definition
*******************************************************************************/
BOOL GetPauseState()
{
	return cur_pause_state;
}

static UINT8 m_pause_on_screen;

void ShowPauseOSDOnOff(UINT8 flag)
{
    OBJECT_HEAD* obj;
    obj= (OBJECT_HEAD*)&win_pause_bmp;

    if (flag != m_pause_on_screen)
    {
        if(flag)
            api_inc_wnd_count();
    }

    if(flag)
        OSD_DrawObject(obj, C_UPDATE_ALL);
    else
        OSD_ClearObject(obj, 0);

    if (flag != m_pause_on_screen)
    {
        if (!flag)
            api_dec_wnd_count();
        m_pause_on_screen = flag;
    }
}


void ShowPauseOnOff(void)
{
    ShowPauseOSDOnOff(cur_pause_state==PAUSE_STATE);
}

static void set_vpo_playmode(UINT32 param)
{
	struct vpo_device *vpo_old = (struct vpo_device *)dev_get_by_id(HLD_DEV_TYPE_DIS, 0);
#ifdef DUAL_VIDEO_OUTPUT    
	struct vpo_device *vpo_new = (struct vpo_device *)dev_get_by_id(HLD_DEV_TYPE_DIS, 1);
#else
    struct vpo_device *vpo_new = NULL;
#endif	
	vpo_ioctl(vpo_old,VPO_IO_PLAYMODE_CHANGE,param);	
	if(vpo_new != NULL)
		vpo_ioctl(vpo_new,VPO_IO_PLAYMODE_CHANGE,param);
}

void SetPauseOnOff(BOOL showOsd)
{
#ifndef NEW_DEMO_FRAME
    if(cur_pause_state==UNPAUSE_STATE)
    {
        cur_pause_state = PAUSE_STATE;
		set_vpo_playmode(NORMAL_2_ABNOR);
        UIChChgPauseProg();
    }
    else
    {
        cur_pause_state = UNPAUSE_STATE;
		set_vpo_playmode(ABNOR_2_NORMAL);
        UIChChgResumeProg();
    }
#else
	if(cur_pause_state==UNPAUSE_STATE)
    	{
        	cur_pause_state = PAUSE_STATE;
		set_vpo_playmode(NORMAL_2_ABNOR);
		api_video_set_pause(1);
    	}
    	else
    	{
        	cur_pause_state = UNPAUSE_STATE;
		set_vpo_playmode(ABNOR_2_NORMAL);
		api_video_set_pause(0);
    	}
#endif

    if(showOsd)
        ShowPauseOnOff();
}

void GetPauseRect(OSD_RECT* rect)
{
	POBJECT_HEAD obj;

	obj = (POBJECT_HEAD)&win_pause_bmp;
	*rect = obj->frame;
}

